#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
	int height,width,step,channels;
      	uchar *data, c;
        int j,k,i;
	float w;
	int s,h, xa;

	int a,b,z, select;
	cout<<"*********************************************************"<<endl;
	cout<<"*** [0] a*X + bY = z     ********************************"<<endl;
	cout<<"*** [1] a*sin(x) + bY = z  ******************************"<<endl;
	cout<<"*** [1] a*cos(x) + bY = z  ******************************"<<endl;
	cout<<"*********************************************************"<<endl;
	cout<<"selct:";
	cin>>select;
	cout<<"a: ";
	cin>>a;
	cout<<"b: ";
	cin>>b;
	cout<<"z: ";
	cin>>z;
        
	IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );

	 // get the image data
        height    = img->height;
        width     = img->width;
        step      = img->widthStep;
        channels  = img->nChannels;
        data      = (uchar *)img->imageData;

        // create a window
        cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
        cvMoveWindow("mainWin", 100, 100);
	
	/*
	for(i=0; i<height; i++){
		for(j=0; j<width; j++){
			if((i >= ((height/2) - 1) && i <= (height / 2) + 1) || (j >= (width/2 - 1) && j <= (width/2 + 1))) {
				c = 0xff;
			} else {
				c = 0x0;
			}
			for(k=0; k<channels; k++){
				data[i*step + j*channels + k] = c;
			}
		}
	}
	*/
	cvLine(img, cvPoint(height/2,0), cvPoint(height/2,width), cvScalar(200.0,240.0,240.0,1.0), 1);
	cvLine(img, cvPoint(0,width/2), cvPoint(height,width/2), cvScalar(200.0,240.0,240.0,1.0), 1);
	
	c = 0x88;
		

	for(i=1; i<width; i++) {
		j = (z - a*(i+250))/b - 250;
		for(k=0; k<channels; k++) {
			c = rand() % 255;
			data[j*step + i*channels + k] = c;
		}
	}
       	cvShowImage("mainWin", img );
        cvWaitKey(0);

        // show the image
        cvSaveImage("wa.jpg", img);
        // wait for a key

        // release the image
        cvReleaseImage(&img );
        return 0;
}
